#include<bits/stdc++.h>
#include "game.h"
#define within :
using namespace std;
const int N=5005;
int f[N][N];bool vis[N];
vector<int>ans;
vector<int>guess(int n,int lim){
  vector<int>G;
  for(int i=1;i<=n;i++) G.emplace_back(i),ans.emplace_back(0);
  int k=count(G);
  for(int i=1;i<=n;i++){
    for(int j=i+1;j<=n;j++){
      swap(G[i-1],G[j-1]),f[j][i]=f[i][j]=count(G),swap(G[i-1],G[j-1]);
      if(f[i][j]==k-2){vis[i]=1;vis[j]=1;}
    }
  }if(k==1){
    for(int i=1;i<=n;i++){
      bool flg=1;
      for(int j=1;j<=n;j++)
        if(i!=j&&f[i][j]!=0){flg=0;break;}
      if(flg){vis[i]=1;break;}
    }
  }vector<int>p;
  for(int i=1;i<=n;i++) if(!vis[i]) p.emplace_back(i);else ans[i-1]=i;
  vector<int>E[N];
  for(int i=0;i<p.size();i++)
    for(int j=i+1;j<p.size();j++){
      if(f[p[i]][p[j]]==k+2) ans[p[i]-1]=p[j],ans[p[j]-1]=p[i];
      else if(f[p[i]][p[j]]==k+1) E[p[i]].emplace_back(p[j]),E[p[j]].emplace_back(p[i]);
    }
  for(int i=1;i<=n;i++){
    if(E[i].size()&&!vis[i]){
      vector<int>tmp;
      int j=i,lst=E[i][0];
      while((j!=i||!tmp.size())){
        int p=E[j][0];
        if(p==lst) p=E[j][1];
        tmp.emplace_back(p);
        lst=j;j=p;
      }//for(int j within tmp) cerr<<j<<' ';cerr<<endl;
      for(int j=0;j<tmp.size()-1;j++)
        G[tmp[j]-1]=tmp[j+1];G[tmp.back()-1]=tmp[0];
      // for(int j within G) cerr<<j<<' ';
      int p=count(G);
      if(p!=k){
        for(int j=0;j<tmp.size()-1;j++)
          ans[tmp[j]-1]=tmp[j+1];ans[tmp.back()-1]=tmp[0];
      }else{
        for(int j=1;j<tmp.size();j++)
          ans[tmp[j]-1]=tmp[j-1];ans[tmp[0]-1]=tmp.back();
      }
      for(int j within tmp) G[j-1]=j,vis[j]=1;
    }
  }//for(int i within ans) cerr<<i<<' ';
  return ans;
}